package com.zy.map;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author Gong
 * @Description
 * @dATE 2021/12/6 16:59
 **/
public class MapTest {
    public static void main(String[] args) throws IOException {
        Map<String,Integer> map = new HashMap<String,Integer>();
        map.put("张三",90);
        map.put("张三1",100);
        map.put("张三2",80);
        map.put("张三3",70);

        Map<String,Integer> res = sortMapByValues(map);
        for (String key:res.keySet()) {
            System.out.println(key+"："+map.get(key));
        }
    }
    public static <K extends Comparable, V extends Comparable> Map<K, V> sortMapByValues(Map<K, V> aMap) {
        HashMap<K, V> finalOut = new LinkedHashMap<>();
//        aMap.entrySet()
//                .stream()
//                .sorted((p1, p2) -> p1.getValue().compareTo(p2.getValue()))
//                .collect(Collectors.toList()).forEach(ele -> finalOut.put(ele.getKey(), ele.getValue()));
        return finalOut;
    }
}
